/**
 * @name 流程的js类
 * @author Yang
 * @date 2018-07-17
 * @version 1.0.1
 * */
var Flow= function () {

    var submitHandler=function () {
        $('form').validate({
            rules:{
                name:"required",
                remote:{
                    url:"validate",
                    type:"get",
                    data:{
                        name:function () {
                            return $("#name").val();
                        },
                        typeId:function () {
                            return typeId;
                        }
                    }
                }
            },
            messages:{
                name:{
                    required:"必填",
                    remote:"该权限的名称已经存在"
                }
            },
            submitHandler: function (form) {
                var params={};
                params.name= $('#name').val();
                params.typeId= typeId;
                params.fileType= $('input[name= fileType]:checked').val();
                params.auditType= $('input[name=auditType]:checked').val();
                params.dateType= $('input[name=dataType]:checked').val();
                params.flowStatus=$('input[name=status]:checked').val();
                if ($('input[name=form]:checked').length>0){
                    var forms=[];
                    $('input[name=form]:checked').each(function () {
                        forms.push($(this).val());
                    })
                    params.forms= forms;
                }
                if ($('input[name=flow]:checked').length>0){
                    var flows=[];
                    $('input[name=flow]:checked').each(function () {
                        flows.push($(this).val());
                    })
                    params.flows= flows;
                }
                params= JSON.stringify(params);
                $.ajax({
                    type:"post",
                    url:"submit",
                    data:{"params":params},
                    dataType:"json",
                    success:function (data) {
                        Common.alert(data);
                        if (data.success){
                            setTimeout(function () {
                                location.href="index.html?typeId="+typeId;
                            },1500)
                        }
                    }
                })
            }
        })
    };

    return {
        submit:function () {
            submitHandler();
        }
    }
}();